
package wuziqi;
import java.util.Random;
// 随机AI
class RandomAI implements AI {
    private Random random = new Random();
    
    @Override
    public int[] makeMove(GameState state, GameConfig config) {
        char[][] board = state.getBoard();
        int size = config.getBoardSize();
        char empty = config.getEmptySymbol();
        
        // 收集所有空位置
        int emptyCount = 0;
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                if (board[i][j] == empty) {
                    emptyCount++;
                }
            }
        }
        
        if (emptyCount == 0) return null;
        
        // 随机选择一个空位置
        int target = random.nextInt(emptyCount); // [0,emptyCount)的整数
        int count = 0;
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                if (board[i][j] == empty) {
                    if (count == target) {
                        return new int[]{i, j};
                    }
                    count++;
                }
            }
        }
        
        return null;
    }
}
